package com.hspedu.homework.homework13;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/1/24
 * @time 20:26
 */
public class Homework13 {
    public static void main(String[] args) {
        Person[] people = new Person[4];
        Person p1 = new Teacher("jack","男",30,7);
        Person p2 = new Teacher("bob","男",15,2);
        Person p3 = new Student("lucy","女",17,00023101);
        Person p4 = new Student("tom","男",18,00023102);
        people[0] = p1;
        people[1] = p2;
        people[2] = p3;
        people[3] = p4;

        Homework13 homework13 = new Homework13();
        homework13.bubbleSort(people);
        homework13.test(p1);
        homework13.test(p3);
    }

    public void test(Person person){
        System.out.println(person.play());
    }

    public void bubbleSort(Person[] people) {
        int[] ageArr = new int[people.length];
        for (int i = 0; i < ageArr.length; i++) {
            ageArr[i] = people[i].getAge();
        }

        for (int i = 1; i <= ageArr.length - 1; i++) {
            for (int j = 1; j <= ageArr.length - i; j++) {
                int temp = 0;
                if (ageArr[j - 1] > ageArr[j]) {
                    temp = ageArr[j - 1];
                    ageArr[j - 1] = ageArr[j];
                    ageArr[j] = temp;
                }
            }
        }

        for (int i = 0; i < ageArr.length; i++) {
            for (int i1 = 0; i1 < people.length; i1++) {
                if (ageArr[i] == people[i1].getAge()) {
                    System.out.println(people[i1]);
                }
            }
        }
    }
}
